package com.av.bcacc.myapidemo.base;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class BaseReclyerviewPagerAdapter<T, V extends ViewDataBinding> extends RecyclerView.Adapter {


    public List<T> data;
    private ReclyerViewCallBack mReclyerViewCallBack;

    public BaseReclyerviewPagerAdapter(List<T> data) {
        this.data = data;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(), parent, false);
        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mReclyerViewCallBack) {
                    mReclyerViewCallBack.onItemClick(v, (int) v.getTag());
                }
            }
        });

        return new BaseReclyerviewHolder<V>(rootView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        holder.itemView.setTag(position);
        onBindRecyclerVeiwHolder((BaseReclyerviewHolder) holder, position);
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public abstract int getLayoutId();


    public abstract void onBindRecyclerVeiwHolder(BaseReclyerviewHolder h, int p);

    public void setReclyerViewCallBack(ReclyerViewCallBack mReclyerViewCallBack) {
        this.mReclyerViewCallBack = mReclyerViewCallBack;
    }

    
}
